package airthmetic.exercise.backtrack;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;

public class _78_子集 {


    public List<List<Integer>> subsets(int[] nums) {

        Deque<Integer> queue = new ArrayDeque();
        List<List<Integer>> res = new ArrayList<List<Integer>>();
        backtrack(nums,0,queue,res);
        return res;
    }

    public void backtrack(int[] nums, int start, Deque<Integer> queue, List<List<Integer>> res){
        res.add(new ArrayList<Integer>(queue));

        for(int i=start; i< nums.length; i++){
            queue.addLast(nums[i]);

            backtrack(nums,i+1,queue,res);

            queue.removeLast();
        }
    }
}
